package org.javaboy.consumer.controller;

import org.javaboy.commons.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@Service
public class CallUserService {
    @Autowired
    RestTemplate restTemplate;

    public User getUserById(Integer id, String token) {
        return restTemplate.getForObject("http://provider/user?id=" + id, User.class);
    }


    public User addUser(User user) {
        return restTemplate.postForObject("http://provider/user", user, User.class);
    }

    public void deleteUser(Integer id) {
        restTemplate.delete("http://provider/user/{id}", id);
    }

    public void updateUser(User user) {
        restTemplate.put("http://provider/user", user);
    }
}
